package inge_soft.gestoriusNuevo.business.controller.validation;

import inge_soft.gestoriusNuevo.business.service.abstraction.IUsuarioService;

import java.util.Map;

import org.zkoss.bind.Property;
import org.zkoss.bind.ValidationContext;
import org.zkoss.bind.validator.AbstractValidator;
import org.zkoss.zk.ui.select.annotation.VariableResolver;
import org.zkoss.zk.ui.select.annotation.WireVariable;


@VariableResolver(org.zkoss.zkplus.spring.DelegatingVariableResolver.class)
public class LoginValidator extends AbstractValidator {
	@WireVariable("usuarioService")
	private IUsuarioService usuarioService;

	
	
	public LoginValidator(){
		
	}
	public void validate(ValidationContext ctx) {
		// all the bean properties
		Map<String, Property> beanProps = ctx.getProperties(ctx.getProperty().getBase());
		validateVacios(ctx);
	
	}
	
	private void validateVacios(ValidationContext ctx){
		Map<String, Property> beanProps = ctx.getProperties(ctx.getProperty().getBase());
		
		if((String) beanProps.get("nick").getValue() == null
				||(String) beanProps.get("nick").getValue() == "")
			this.addInvalidMessage(ctx, "error","No puede dejar campos vacios.");
		if((String) beanProps.get("contrasenia").getValue() == null 
				|| (String) beanProps.get("contrasenia").getValue() == "")
			this.addInvalidMessage(ctx, "error","No puede dejar campos vacios.");
	}

}
